<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
class m_admin extends spModel{
	public $table = 'admin';
	public $pk = 'id';
	//自动验证
	public $verifier = array(
		'rules'=>array(
			'code'=>array(
				'notnull'=>true,
			),
			'name'=>array(
				'notnull'=>true,
			),
			'pswd'=>array(
				'notnull'=>true,
			),
		),
	);
	//关联分组表
	public $linker = array(
		array(
			'type'=>'hasone', //一对一关联
			'map'=>'group', //关联标识
			'mapkey'=>'gid', //本表关联字段
			'fclass'=>'m_group', //对应表类名
			'fkey'=>'id', //对应表关联字段
			'enabled'=>true, //启用关联
		),
	);
	public function check($code, $pswd){
		return ($_SESSION['admin'] = $this->find(array('code'=>$code, 'pswd'=>md5('vonuo'. $pswd . 'com')))) ? true : false;
	}
	public function getip(){
		if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
			$ip = getenv('HTTP_CLIENT_IP');
		} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
			$ip = getenv('HTTP_X_FORWARDED_FOR');
		} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
			$ip = getenv('REMOTE_ADDR');
		} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
	}
}
